<?php
/**
* @description This widget display list of active content types in a dropdown. 
* When user choose a type, a JS callback function will be called.
*/
class ContentTypeDropDown extends CWidget
{
    /**
    * @var string name of JS callback function
    */
    public $Callback;
    
    /**
    * Array of model paths, if specified, only list content type of these models
    * @var array
    */
    public $Models;
    
    /**
    * @var bool whether to include base types such as text, image, video
    * Note that Core types belong to Cms module so models are always Cms.models
    */
    public $IncludeCoreTypes = true;
    
    public function run() {
        $models = array();
        $result = FSM::_run('Cms.ContentType.findAll', array('includeCoreTypes' => $this->IncludeCoreTypes));
        if ($result->hasErrors() === false)
        {
            $models = $result->data;
            if (count($models))
            {
                $models = CHtml::listData($models, 'model', 'name');
            }
        }

        $this->render('ContentTypeDropDown', array(
            'models' => $models,
        ));
    }
}
